package com.backend.modules.system.repository;

import com.backend.modules.system.entity.SysDepartment;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface SysDepartmentRepository extends JpaRepository<SysDepartment, Long> {
    
    List<SysDepartment> findByParentIdOrderBySort(Long parentId);
    
    @Query("SELECT d FROM SysDepartment d WHERE d.parentId IS NULL ORDER BY d.sort")
    List<SysDepartment> findRoots();
    
    boolean existsByNameAndParentId(String name, Long parentId);

}